package com.imooc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 *
 * @auther Levi
 * @Date: 2021/03/19/9:24
 * @Description:
 */
public class AdminTokenInterceptor extends BaseInterceptor implements HandlerInterceptor {



    /**
     * 进入controller之前调用
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userId = request.getHeader("adminUserId");
        String userToken = request.getHeader("adminUserToken");
//        System.out.println("userid: "+userId+"userToken: "+userToken);

        boolean run = verifyUserIdToken(userId, userToken, REDIS_ADMIN_TOKEN);
        System.out.println("是否登录："+run);

        return true;
    }

    /**
     * 进入controller之后,渲染视图之前
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }
    /**
     * 进入controller之后,渲染视图之后
     * @param request
     * @param response
     * @param handler
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
